<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Input;//引入input
use App\Admin\Auth;
class AuthController extends Controller
{
    //权限列表
    public function index(){
    	//获取数据
    	$data = Auth::get();
    	return view('admin.auth.index',['data' => $data]);
    }

    //权限添加
    public function add(){
    	//判断请求类型
    	//echo Input::method();die;
    	if(Input::method() == 'POST'){
    		//数据入库
    		//必要的验证过程
    		$data = Input::all();	//获取全部数据
    		unset($data['_token']);
    		$result = Auth::insert([
    				'auth_name'		=>	$data['auth_name'],
    				'controller'	=>	$data['controller'],
    				'action'		=>	$data['action'],
    				'is_nav'		=>	$data['is_nav'],
    				'pid'			=>	$data['pid']
    		]);//返回bool值
    		return $result ? '1' : '0';
    	}else{
    		//获取顶级权限
    		$auth = Auth::where('pid','0') -> get();
    		return view('admin.auth.add',['auth' => $auth]);
    	}
    }
}
